import java.util.Scanner;

public class StringUtil {
    public static String inverseAndConvert(String s) {
        //将字符串s逆置
        String reversed = new StringBuilder(s).reverse().toString();
        //判断逆置前后是否相等
        if (s.equalsIgnoreCase(reversed)) {
            return reversed.toUpperCase();
        } else {
            return reversed.toLowerCase();
        }
    }

    public static int statistic(String s1, String s2) {
        //判断子串是否为空
        if (s2.isEmpty()) {
            return 0;
        }
        //将子串转化为正则表达式，统计原串中匹配子串的个数
        int count = (s1 + "").split(s2).length - 1;
        return count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String s1 = scanner.nextLine();
        //测试字符串逆置方法
        String s1Inverse = StringUtil.inverseAndConvert(s1);
        System.out.println("逆置并大小写转换后的结果为：" + s1Inverse);
        System.out.println();

        System.out.println("请输入原字符串：");
        String s2 = scanner.nextLine();
        System.out.println("请输入子字符串：");
        String s3 = scanner.nextLine();
        //测试字符串统计方法
        int cnt = StringUtil.statistic(s2, s3);
        System.out.println("子串在原串中出现的次数为：" + cnt);
    }
}
